package com.example.demoyyy.common;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/*全局异常处理*/
@ControllerAdvice(annotations = {RestController.class, Controller.class})
@ResponseBody
public class GlobalExceptionHandler {
    @ExceptionHandler(CustomException.class)
    public R<Object> exceptionHandler(CustomException ex){
        System.out.println("exceptionHandler是"+ex.getMessage());
        return R.error(0,ex.getMessage(),null);
    }
}
